package com.zhen.generator.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据库驱动器枚举类。
 * 
 * @author Luffy
 *
 */
public enum DBTypeEnum {
    // Mysql
    MYSQL("mysql", "com.mysql.jdbc.Driver"),

    // Oracle
    ORACLE("oracle", "oracle.jdbc.dirver.OracleDriver"),

    // SQLServer2000
    SQLSERVER2000("sqlserver2000",
            "com.microsoft.jdbc.sqlserver.SQLServerDriver"),

    // SQLServer2005
    SQLSERVER2005("sqlserver2005",
            "com.microsoft.sqlserver.jdbc.SQLServerDriver"),

    // JTDs for SQLServer
    JTDS("jtds", "net.sourceforge.jtds.jdbc.Driver"),

    // Sybase
    SYBASE("sybase", "com.sybase.jdbc.SybDriver"),

    // DB2
    DB2("db2", "com.ibm.db2.jdbc.app.DB2Driver"),

    // HsqlDB
    HSQLDB("hsqldb", "org.hsqldb.jdbcDriver"),

    // Derby
    DERBY("derby", "org.apache.derby.jdbc.ClientDriver"),

    // H2
    H2("h2", "org.h2.Driver"),

    // PostgreSql
    POSTGRESQL("postgresql", "org.postgresql.Driver");

    private String type;

    private String driver;

    private DBTypeEnum(String type, String driver) {
        this.type = type;
        this.driver = driver;
    }

    public String getType() {
        return type;
    }

    public String getDriver() {
        return driver;
    }

    /**
     * 返回数据库驱动数组。
     * 
     * @return
     */
    public static String[] getDBDrivers() {
        List<String> drivers = new ArrayList<String>();
        for (DBTypeEnum dbType : values()) {
            drivers.add(dbType.getDriver());
        }
        return drivers.toArray(new String[0]);
    }

}
